<template>
  <div>
    <template>
      <el-table :data="lst">
        <el-table-column prop="id" label="编号"> </el-table-column>
        <el-table-column prop="name" label="资源"> </el-table-column>
        <el-table-column prop="url" label="地址"> </el-table-column>
        <el-table-column prop="url" label="地址">
          <template slot-scope="scope">
            <!-- 按钮权限 -->
            <el-button
              type="text"
              size="small"
              @click="ck(scope.row.id)"
              v-if="butt.includes(4)"
              >查看</el-button
            >
            <el-button
              type="text"
              size="small"
              @click="ck(scope.row.id)"
              v-if="butt.includes(2)"
              >查看1</el-button
            >
          </template>
        </el-table-column>
      </el-table>
    </template>
    <el-dialog title="按钮配置" :visible.sync="dialogTableVisible">
      <el-checkbox-group v-model="checkList" v-for="(i, x) in an" :key="x">
        <el-checkbox :label="i.key">{{ i.label }}</el-checkbox>
      </el-checkbox-group>
      <el-button @click="ti">提交</el-button>
    </el-dialog>
  </div>
</template>
  
  <script>
export default {
  data() {
    return {
      aid: 0,
      lst: "",
      an: "",
      butt: "",
      dialogTableVisible: false,
      checkList: [],
      roleid: localStorage.getItem("roleid"),
      // 获取当前页面的url
      url: this.$route.path,
    };
  },
  mounted() {
    this.getresou();
    this.getpager();
    this.getbut();
  },
  methods: {
    getresou() {
      this.axios.get("/getres").then((res) => {
        this.lst = res.data.data;
      });
    },
    getpager() {
      this.axios.get("/getbutton").then((res) => {
        this.an = res.data.data;
      });
    },
    ck(id) {
      this.aid = id;
      this.dialogTableVisible = true;
    },
    ti() {
      this.axios
        .post("/but", {
          resourceid: this.aid,
          checkList: this.checkList,
          roleid: this.roleid,
        })
        .then((res) => {
          alert(res.data.msg);
        });
    },
    // 页面权限
    getbut() {
      var data = { url: this.url, roleid: this.roleid };
      this.axios.post("/getbut", data).then((res) => {
        this.butt = res.data.data;
      });
    },
  },
};
</script>
  
  <style>
</style>